﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Altairis.MailToolkit.ListManager.Pages.Admin {
    public partial class SendMessage : System.Web.UI.Page {

        protected void Page_Init(object sender, EventArgs e) {
            // Populate dropdown with mailing list names
            foreach (MailingListProvider list in MailingListManager.Lists) {
                this.ListName.Items.Add(new ListItem(string.Format(Resources.UI.ListInfoDisplayFormat, list.Name, list.Description, list.GetMemberCount()), list.Name));
            }
        }

        protected void SubmitButton_Click(object sender, EventArgs e) {
            if (!this.IsValid) return;

            var baseUrl = new UriBuilder(this.Request.Url) { Path = "", Query = "" };

            MailingListManager.SendMessages(this.ListName.SelectedValue, this.SubjectTextBox.Text, this.BodyTextBox.Text, baseUrl);
            this.MultiViewPage.SetActiveView(this.ViewResult);
        }

        protected void BackButton_Click(object sender, EventArgs e) {
            this.Response.RedirectToRoute("AdminHomePage");
        }

    }
}